package br.com.pfc.application.dao;

import br.com.pfc.model.Endereco;
import java.io.Serializable;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.TransactionPropagationType;
import org.jboss.seam.annotations.Transactional;

/**
 *
 * @author Vanda
 */
@AutoCreate
@Name("enderecoDAO")
@Transactional(TransactionPropagationType.SUPPORTS)
public class EnderecoDAO implements Serializable {

    @In
    private Session pfc;

    public Endereco obterPorId(Integer idEndereco){
        Criteria c = pfc.createCriteria(Endereco.class);
        c.add(Restrictions.eq("idEndereco", idEndereco));
        return (Endereco) c.uniqueResult();
    }

    public void alterar(Endereco endereco) {
        pfc.update(endereco);
        pfc.flush();
    }

    public void salvar(Endereco endereco) {
        try {
            pfc.save(endereco);
            pfc.flush();
        } catch (Exception e) {
            System.out.println("Exceção : " + e);
        }
    }

    public void excluir(Endereco endereco) {
        pfc.flush();
        pfc.delete(endereco);
    }
}
